Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-ai #264

Merged
merged 40 commits into from
Feb 6, 2025
Merged

dev-ai #264

merged 40 commits into from
Feb 6, 2025

Conversation

Bistard
Copy link
Owner

@Bistard Bistard commented Feb 1, 2025

Summary by Sourcery

New Features:

  • new service: IAITextService: Integrate OpenAI and DeepSeek AI text models for text generation.
  • new service: IEncryptionService: support encryption/decryption functionality
  • new registrant: AIModelRegistrant
    • new base class: LLMModel
    • new base class: TextSharedOpenAIModel
    • new model: TextGPTModel
    • new model: TextDeepSeekModel
  • new error: AIError for standardized error handling relates to LLM

Copy link
Contributor

sourcery-ai bot commented Feb 1, 2025

Reviewer's Guide by Sourcery

This pull request introduces AI text generation capabilities using OpenAI and DeepSeek models. It includes new services for AI text generation and encryption, along with corresponding models and error handling. The changes also involve integrating these services into the application, allowing users to leverage AI for text-related tasks.

Sequence diagram for AI text request flow

sequenceDiagram
    participant Browser
    participant BrowserChannel as BrowserAITextChannel
    participant MainService as MainAITextService
    participant Model as AI Model
    participant API as AI Provider API

    Browser->>BrowserChannel: sendRequest(options)
    BrowserChannel->>MainService: IPC call: sendRequest
    MainService->>Model: sendRequest(options)
    Model->>API: API request
    API-->>Model: Response
    Model-->>MainService: Formatted response
    MainService-->>BrowserChannel: IPC response
    BrowserChannel-->>Browser: AI.Text.Response
Loading

Class diagram for AI text service and models

classDiagram
    class IAITextService {
        <<interface>>
        +init()
        +switchModel(options)
        +updateAPIKey(newKey, modelType, persisted)
        +sendRequest(options)
        +sendRequestStream(options, onChunkReceived)
    }

    class LLMModel {
        <<abstract>>
        +modality: AI.Modality
        +name: AI.ModelName
        +apiKey: string
        +setAPIKey(newKey)
    }

    class TextSharedOpenAIModel {
        <<abstract>>
        +modality: AI.Modality.Text
        +name: AI.ModelName
        +apiKey: string
        +setAPIKey(newKey)
        +sendRequest(options)
        +sendRequestStream(options, onChunkReceived)
    }

    class TextGPTModel {
        +name: AI.ModelName.ChatGPT
    }

    class TextDeepSeekModel {
        +name: AI.ModelName.DeepSeek
    }

    LLMModel <|-- TextSharedOpenAIModel
    TextSharedOpenAIModel <|-- TextGPTModel
    TextSharedOpenAIModel <|-- TextDeepSeekModel

    note for TextSharedOpenAIModel "Base class for OpenAI-compatible models"
    note for LLMModel "Base class for all LLM models"
Loading

File-Level Changes

Change Details Files
Introduces a new service for AI text generation, integrating OpenAI and DeepSeek models.
  • Defines the IAITextService interface and its implementation MainAITextService.
  • Adds methods for initializing, switching, and sending requests to AI models.
  • Integrates with IConfigurationService and IMainStatusService for API key management.
  • Introduces AIError for standardized error handling.
  • Adds TextGPTModel and TextDeepSeekModel for handling OpenAI and DeepSeek models respectively.
  • Introduces LLMModel as a base class for all LLM-related models.
  • Adds AIModelRegistrant to register different AI models.
  • Adds BrowserAITextChannel and MainAITextChannel for IPC communication.
src/platform/ai/electron/mainAITextService.ts
src/platform/ai/common/aiText.ts
src/platform/ai/electron/openAIModel.ts
src/platform/ai/electron/GPTModel.ts
src/platform/ai/electron/deepSeekModel.ts
src/platform/ai/common/ai.ts
src/platform/ai/electron/llmModel.ts
src/platform/ai/common/aiModel.register.ts
src/platform/ai/common/aiTextChannel.ts
Implements encryption/decryption functionality for sensitive data like API keys.
  • Defines the IEncryptionService interface and its implementation MainEncryptionService.
  • Uses safeStorage in Electron to encrypt and decrypt data.
  • Provides methods for checking encryption availability and setting plain text encryption.
src/platform/encryption/electron/mainEncryptionService.ts
src/platform/encryption/common/encryptionService.ts
Registers AI models and configures the application to use them.
  • Registers AIModelRegistrant in the main process.
  • Adds IAITextService to the main and renderer instantiation services.
  • Configures the application to use AI text models.
  • Integrates AI-related configurations into the settings.
  • Adds encryption support for status keys in the inspector.
  • Adds AIModel registrant type.
src/code/electron/app.ts
src/code/browser/renderer.desktop.ts
src/platform/registrant/common/registrant.ts
src/platform/configuration/common/configurationRegistrant.ts
src/workbench/services/workbench/configuration.register.ts
src/code/browser/inspector/inspectorItemRenderer.ts
src/code/browser/inspector/inspectorTree.ts
src/code/browser/inspector/renderer.inspector.ts
Standardizes error handling for LLM operations with the introduction of AIError.
  • Introduces the AIError class for encapsulating LLM-related errors.
  • Provides detailed error information, including model name, category, HTTP status, and more.
  • Improves error reporting and handling throughout the AI-related services.
src/base/common/error.ts
Improves type safety and code quality.
  • Adds AsyncOnly type to ensure all functions in an object return Promise.
  • Updates unwrapChannel function to support AsyncOnly type.
src/base/common/utilities/type.ts
src/platform/ipc/common/proxy.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Bistard - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The MainAITextService returns GPTModel for both TextModelType.GPT and TextModelType.DeepSeek. If DeepSeek should have different behavior, it needs its own model implementation.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/platform/ai/electron/mainAITextService.ts Outdated Show resolved Hide resolved
src/base/common/json.ts Show resolved Hide resolved
@Bistard
Copy link
Owner Author

Bistard commented Feb 3, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Bistard - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider standardizing error handling approach across the codebase - currently mixing Result types and direct throws/panics. Pick one consistent pattern for better reliability.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/platform/ai/electron/openAIModel.ts Outdated Show resolved Hide resolved
@Bistard
Copy link
Owner Author

Bistard commented Feb 4, 2025

Sample usage for sending text:

image

@Bistard
Copy link
Owner Author

Bistard commented Feb 4, 2025

@sourcery-ai guide

@Bistard Bistard changed the title Dev ai dev-ai Feb 4, 2025
@Bistard Bistard merged commit 65526e2 into dev Feb 6, 2025
10 checks passed
@Bistard Bistard deleted the dev-ai branch February 7, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants